package flc.ast.adapter;

import android.view.View;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.stark.poster.PosterConst;
import com.stark.poster.PosterStyle;

import java.util.List;

import androidx.annotation.Nullable;

import flc.ast.R;
import stark.common.basic.utils.AssetUtil;

public class MyPosterAdapter extends BaseQuickAdapter<PosterStyle, BaseViewHolder> {


    int mCurPos = 0;

    public MyPosterAdapter(int layoutResId, @Nullable List<PosterStyle> data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(BaseViewHolder baseViewHolder, PosterStyle posterStyle) {
        String showImage = posterStyle.getShowImage();
        ImageView view = baseViewHolder.getView(R.id.ivPlacardItemImg);
        Glide.with(view)
                .load(AssetUtil.getFilePath(PosterConst.DIR_POSTER_SHOW, showImage))
                .into(view);

        if (mCurPos == baseViewHolder.getAdapterPosition()) {
            baseViewHolder.itemView.setSelected(true);
            baseViewHolder.setVisible(R.id.tvPlacardItemSel,true);
        } else {
            baseViewHolder.itemView.setSelected(false);
            baseViewHolder.setVisible(R.id.tvPlacardItemSel,false);
        }
    }

    @Override
    public void setOnItemClick(View v, int position) {
        super.setOnItemClick(v, position);
        if (mCurPos == position) return;
        notifyItemChanged(mCurPos);
        notifyItemChanged(position);
        mCurPos = position;
    }
}
